package com.yvdedu.my161121.address_book.web.dto;

import java.util.Map;
import java.util.HashMap;
import java.util.List;

import org.springframework.validation.FieldError;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.*;

@JsonInclude(value = Include.NON_NULL)
public class FormResult {

    private boolean status;

    private Map<String, String> errors = new HashMap<String, String>();

    public int getErrorMessage() {
        return errorMessage;
    }

    private int errorMessage;

    private Object data;

    public FormResult(boolean status, Object data) {
        this.status = status;
        this.data = data;
    }


    public FormResult(List<FieldError> fieldErrors) {
        for (FieldError error : fieldErrors) {
            errors.put(error.getField(), error.getDefaultMessage());
        }

    }

    public FormResult(String field, String error) {
        errors.put(field, error);
    }


    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Map<String, String> getErrors() {
        return errors;
    }

    public void setErrors(Map<String, String> errors) {
        this.errors = errors;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public void setErrorMessage(int errorMessage) {
        this.errorMessage = errorMessage;
    }

}
 
